package com.heny.nc.service;

import com.heny.demo.common.CommonErrorCode;
import com.heny.demo.common.CommonException;
import com.heny.nc.model.NCModel;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 * @author litao.cc
 * @version SaveDataProcessorContext.java v0.1 t2025/4/26 18:53
 * @date 2025/4/26 18:53
 * @description SaveDataProcessorContext
 */
@Data
public class SaveDataProcessorContext {
    private Map<Integer, List<NCModel>> data;
    private String path;

    private AbstractSaveDataProcessor processor;
    private String baseFileName;
    private List<String> filePathList;

    public SaveDataProcessorContext(Map<Integer, List<NCModel>> data,String path,String type,String baseFileName){
        this.data = data;
        this.path = path;
        this.baseFileName = baseFileName;
        this.processor = SaveDataProcessorEnum.getByType(type).getProcessor();
    }

    public void execute(){
        if (processor == null) {
            throw new CommonException(CommonErrorCode.SYSTEM_ERROR, "strategy is null");
        }
        List<String> save = processor.apply(this.data, this.path, this.baseFileName);
        this.filePathList = save;
    }
}
